package dubbo;

import com.lagou.rpc.api.DubboTPMoniterService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

/**
 * @Description: TODO
 * @Author 50705 2021/11/23
 **/

@Component
public class ConsumerComponent implements  Runnable {

    @Reference
    private DubboTPMoniterService dubboTPMoniterService;

    public String methodA(String methodA) throws Exception {
        return dubboTPMoniterService.methodA(methodA);
    }

    public String methodB(String methodB) throws Exception {
        return dubboTPMoniterService.methodB(methodB);
    }

    public String methodC(String methodC) throws Exception {
        return dubboTPMoniterService.methodC(methodC);
    }

    public volatile static int i;
    Long time1;
    Long time2;

    @Override
    public void run() {
        i++;
        try {
            if(i%3==1){
                this.methodA("AAA");
            }else if(i%3==2){
                this.methodB("BBB");
            }else {
                this.methodC("CCC");
            }
            if (i % 1000 == 0) {
                if (i % 2000 == 0) {
                    time2 = System.currentTimeMillis();
                    System.out.println("累计处理{}~{}条耗时:{}ms :" + (i-2000) + "~" + i + ":" + (time2 - time1));
                } else {
                    time1 = System.currentTimeMillis();
                }
            }
        }catch (Exception e){

        }

    }
}
